package com.test.browser;

import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Browser {
    private static Logger log = Logger.getLogger(Browser.class);
    public static Properties properties = new Properties();
    static {
        // 解析config.properties获取浏览器配置信息
        try {
            InputStream in = Browser.class.getClassLoader().getResourceAsStream("config.properties");
            properties.load(in);
        } catch (IOException e) {
            log.error("解析发生异常: " + e.getMessage());
        }
    }

    public WebDriver openBrowser(){
        String type = properties.getProperty("browser.type");
        WebDriver driver = null;
        if("chrome".equalsIgnoreCase(type)){
            System.setProperty("webdriver.chrome.driver",properties.getProperty("chrome.webdriver"));
            driver = new ChromeDriver();
            driver.manage().window().maximize();
        }
        return driver;
    }
}
